import { putActionLog } from '@/api/index'
import Qs from 'qs'
import { serverip2 } from '@/api/serverIP'
const JavaPostBaseUrl = {
    ['/Sp/adduser']:'添加用户',
    ['/Sp/updateuser']:'修改用户',
    ['/Sp/deleuser']:'删除用户',
    ['/Sp/addport']:'添加需要监控的端口信息',
    ['/Sp/updateportinfo']:'修改需要监控的端口信息',
}

const NetPostDataOpera = {
    ['CreateServicesName']:'添加业务系统节点',
    ['ModifyServicesName']:'修改业务系统节点',
    ['DeleteServicesName']:'删除业务系统节点',
    ['CreateDBMonitor']:'添加数据库节点',
    ['ModifyDBMonitor']:'修改数据库节点',
    ['CreateHostMonitor']:'添加服务器/网络设备节点',
    ['ModifyHostMonitor']:'修改服务器/网络设备节点',
    ['CreateAlertGroupIndex']:'添加阈值组',
    ['modifyalertlevel']:'修改阈值',
    ['DeleteAlertLevel']:'删除阈值组',
}

const putPleaParam = ({account,event,parameter}) => {
    putActionLog({
        account,event,parameter      
    }).then().catch(_ => {
        console.log('提交失败')
    })
}

const putPleaParamHook = (response) => {
    
    let requestData = '';
    let requestType = '';
    let account = localStorage.getItem("ms_username")
    switch(response.headers['content-type']){
        case 'text/plain; charset=utf-8':
            let postData = JSON.parse(Qs.parse(response.config.data).postData)
            // .net
            requestData = response.config.data
            requestType = NetPostDataOpera[postData.opera]
            if(requestData&&requestType){
                putPleaParam({account,event:requestType,parameter:requestData})
            }
            
            
            break;
        case 'application/json;charset=UTF-8':
            //java
            requestData = response.config.params;
            requestType = JavaPostBaseUrl[response.config.url.split(serverip2)[1]]
            // console.log(response.config.url.split(serverip2)[1])
            if(requestData&&requestType){
                putPleaParam({account,event:requestType,parameter:requestData})
            }

                break;
        default:
            a = 1           

    }
}

export { putPleaParamHook }